class TransportesController < ApplicationController
  active_scaffold :transporte do |config|
    
    #    config.columns = [:ndt, :deposito, :box, :pares, :cxs, :m, :peso, :uf, :tipo, :transportadora, :created_at, :status, :obs_trans]
    #    config.columns.add :etiqueta

    config.label = "Transportes Gerais"
    
    config.create.columns = [:ndt, :deposito, :uf, :tipo, :transportadora, :status, :created_at, :box, :pares, :cxs, :m , :peso, :obs_trans]
    config.update.columns = [:ndt, :deposito, :uf, :tipo, :transportadora, :status, :created_at, :box, :pares, :cxs, :m , :peso, :obs_trans, :etiqueta]
    config.list.columns = [:deposito, :box, :ndt_novo, :pares_novo, :cxs_novo, :m_novo, :peso_novo, :uf, :tipo, :transportadora, :status, :data_inicio, :obs_trans, :etq]    

    config.columns.add :ndt_novo, :pares_novo, :cxs_novo, :m_novo, :peso_novo, :data_inicio
    
    config.theme = :blue
    config.columns[:transportadora].description = "Transportadora"
    config.columns[:uf].description = "Destino"
    config.columns[:tipo].description = "Tipo de envio"
    config.columns[:box].description = "Box"
    config.columns[:deposito].description = "Deposito"
    config.columns[:status].description = "Status"
    config.columns[:obs_trans].description = "Obs. Transp."
    config.columns[:ndt].description = "Número do Transporte:"
    config.columns[:pares].description = "Pares"
    config.columns[:cxs].description = "Caixas"
    config.columns[:m].description = "Volume"
    config.columns[:peso].description = "Peso" 
    
    config.columns[:ndt_novo].label = "NDT"
    config.columns[:pares_novo].label = "PARES"    
    config.columns[:cxs_novo].label = "CXS"    
    config.columns[:m_novo].label = "M"    
    config.columns[:peso_novo].label = "PESO"    
    config.columns[:data_inicio].label = "PESO"       

    config.columns[:ndt].label = "NDT"
    config.columns[:pares].label = "PARES"
    config.columns[:cxs].label = "CAIXAS"
    config.columns[:m].label = "VOLUME"
    config.columns[:peso].label = "PESO"    
    config.columns[:transportadora].label = "TRANSP."
    config.columns[:uf].label = "DESTINO"
    config.columns[:tipo].label = "TIPO"
    config.columns[:box].label = "BOX"
    config.columns[:deposito].label = "DEPOSITO"
    config.columns[:status].label = "STATUS"
    config.columns[:obs_trans].label = "OBS"
    
    config.columns[:tipo].ui_type = :select
    config.columns[:deposito].ui_type = :select
    config.columns[:transportadora].ui_type = :select    
    config.columns[:uf].ui_type = :select    
    config.columns[:status].ui_type = :select    
    
    config.list.sorting = [{:deposito => 'DESC'}]
    config.list.per_page = 100000
    
    config.create.link.label = "NOVO"
    config.search.link.label = "BUSCA"
    config.show.link.label = "Mostrar"
    config.delete.link.label = "Apagar"
    config.delete.link.confirm = "Apagar?"
    
    #    config.actions.exclude :search
    #    config.actions.exclude :delete
  end
  
  def conditions_for_collection
    ['status_id != ? and status_id != ?','9','17']
  end
  
  def wm
    @transportes = Transporte.find_all_by_status_id([8,10,15], :order => "status_id asc")
    @depositos = Deposito.find(:all, :order => "qtbox desc")
    respond_to  do |format|
      format.html
    end
  end
  
  def wm_geral
    @transportes = Transporte.find_all_by_status_id([1,3,4,12,13,14], :order => "status_id asc")
    @depositos = Deposito.find(:all, :order => "qtbox desc")    
    respond_to  do |format|
      format.html
    end
  end
  
  def celcli
    @transportes = Transporte.find_all_by_status_id([8,10,15], :order => "status_id asc")
    @depositos = Deposito.find(:all, :order => "qtbox desc")
    respond_to  do |format|
      format.html
    end
  end
  
  def resumo
    @depositos = Deposito.find(:all, :order => "qtbox desc")
    respond_to do |format|
      format.html
    end
  end
  
  module TransportesHelper   
    def list_row_class(record)     
      record.ndt == 66548  ? 'faturado' : 'normal'   
    end 
  end
  
  protected
  
  def before_save(record,status)
    #    if record.status_id == Status.find(status)
    #      record.ended_at = DateTime.now
    #    end
  end

end
